package com.nmsl.medicine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.medicine.domain.MedicineStorageOutRecord;
import com.nmsl.medicine.service.IMedicineStorageOutRecordService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 药品出库记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/medicine/outrecord")
public class MedicineStorageOutRecordController extends BaseController
{
    @Autowired
    private IMedicineStorageOutRecordService medicineStorageOutRecordService;

    /**
     * 查询药品出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicineStorageOutRecord medicineStorageOutRecord)
    {

        System.out.println(medicineStorageOutRecord);
        startPage();
        List<MedicineStorageOutRecord> list = medicineStorageOutRecordService.selectMedicineStorageOutRecordList(medicineStorageOutRecord);
        return getDataTable(list);
    }

    /**
     * 导出药品出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:export')")
    @Log(title = "药品出库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicineStorageOutRecord medicineStorageOutRecord)
    {
        List<MedicineStorageOutRecord> list = medicineStorageOutRecordService.selectMedicineStorageOutRecordList(medicineStorageOutRecord);
        ExcelUtil<MedicineStorageOutRecord> util = new ExcelUtil<MedicineStorageOutRecord>(MedicineStorageOutRecord.class);
        util.exportExcel(response, list, "药品出库记录数据");
    }

    /**
     * 获取药品出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:query')")
    @GetMapping(value = "/{storageOutId}")
    public AjaxResult getInfo(@PathVariable("storageOutId") Long storageOutId)
    {
        return success(medicineStorageOutRecordService.selectMedicineStorageOutRecordByStorageOutId(storageOutId));
    }

    /**
     * 新增药品出库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:add')")
    @Log(title = "药品出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicineStorageOutRecord medicineStorageOutRecord)
    {
        return toAjax(medicineStorageOutRecordService.insertMedicineStorageOutRecord(medicineStorageOutRecord));
    }

    /**
     * 修改药品出库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:edit')")
    @Log(title = "药品出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicineStorageOutRecord medicineStorageOutRecord)
    {
        return toAjax(medicineStorageOutRecordService.updateMedicineStorageOutRecord(medicineStorageOutRecord));
    }

    /**
     * 删除药品出库记录
     */
    @PreAuthorize("@ss.hasPermi('medicine:outrecord:remove')")
    @Log(title = "药品出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storageOutIds}")
    public AjaxResult remove(@PathVariable Long[] storageOutIds)
    {
        return toAjax(medicineStorageOutRecordService.deleteMedicineStorageOutRecordByStorageOutIds(storageOutIds));
    }
}
